﻿using DevExpress.XtraEditors.DXErrorProvider;
using Dogshow.Model.Validation;
using FluentValidation.Results;
using Dogshow.Win.Helpers;

namespace Dogshow.Win.Models
{
    public class Kinolog : Model.Kinolog, IValidatable
    {
        public static readonly KinologValidator s_Validator = new KinologValidator();

        public void GetPropertyError(string propertyName, ErrorInfo info)
        {
            this.GetErrorsForProperty(propertyName, info);
        }

        public void GetError(ErrorInfo info)
        {
            this.GetErrors(info);
        }

        public bool IsValid { get; set; }

        public ValidationResult Validate()
        {
            var validationResult = s_Validator.Validate(this);
            IsValid = validationResult.IsValid;
            return validationResult;
        }

        public bool Equals(Kinolog other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id == Id;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(Kinolog)) return false;
            return Equals((Kinolog)obj);
        }

        public override int GetHashCode()
        {
            return Id;
        }
    }
}